package Visao;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import modelo.Musica;
import controle.ControleMusica;

public class TelaCadastroMusica extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField txtTempoFaixa;
	private JButton btnCadastrarMusica;
	private JButton btnCancelar;
	private JButton btnVoltar;
	private JTextField txtNomeMusica;
	private ControleMusica controle;

	private Musica musica = new Musica();
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaCadastroMusica frame = new TelaCadastroMusica();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public TelaCadastroMusica() {
		controle = new ControleMusica();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(192, 192, 192));
		contentPane.setForeground(new Color(255, 255, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Cadastro De Musica");
		lblNewLabel.setFont(new Font("Segoe Script", Font.PLAIN, 16));
		lblNewLabel.setBounds(42, 11, 309, 33);
		contentPane.add(lblNewLabel);
		
		btnCadastrarMusica = new JButton("Cadastrar Musica");
		btnCadastrarMusica.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				 Musica musica = new Musica();
				 musica.setNomeMusica(txtNomeMusica.getText());			 
                 musica.setTempoFaixa(Double.valueOf(txtTempoFaixa.getText()));
                 
                 try {
                	 controle.salvar(musica);
                 } catch (Exception e) {
                	 JOptionPane.showMessageDialog(null, e.getMessage());
                	 e.printStackTrace();
                 }
			}
		});
		btnCadastrarMusica.setBounds(10, 152, 194, 53);
		contentPane.add(btnCadastrarMusica);
		
		JLabel lblNewLabel_1 = new JLabel("Nome da Musica:");
		lblNewLabel_1.setBounds(10, 55, 129, 20);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Tempo de execucao");
		lblNewLabel_2.setBounds(10, 97, 129, 20);
		contentPane.add(lblNewLabel_2);
		
		textField = new JTextField();
		textField.setBounds(9, 86, 40, -6);
		contentPane.add(textField);
		textField.setColumns(10);
		
		txtNomeMusica = new JTextField();
		txtNomeMusica.setBounds(153, 55, 246, 20);
		contentPane.add(txtNomeMusica);
		txtNomeMusica.setColumns(10);
		
		txtTempoFaixa = new JTextField();
		txtTempoFaixa.setBounds(156, 100, 243, 20);
		contentPane.add(txtTempoFaixa);
		txtTempoFaixa.setColumns(10);
		
		btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtNomeMusica.setText(null);
				txtTempoFaixa.setText(null);
				dispose();
			}
		});
		btnCancelar.setBounds(214, 152, 185, 53);
		contentPane.add(btnCancelar);
		
		btnVoltar = new JButton("Voltar");
		btnVoltar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtNomeMusica.setText(null);
				txtTempoFaixa.setText(null);
				TelaEscolhaMetodo escolhaMetodo = new TelaEscolhaMetodo(1);
				escolhaMetodo.setVisible(true);
				setVisible(false);
			}
		});
		btnVoltar.setBounds(121, 216, 178, 46);
		contentPane.add(btnVoltar);
	}

}
